<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
   xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
   xmlns:f="http://xmlns.jcp.org/jsf/core"
   xmlns:h="http://xmlns.jcp.org/jsf/html"
   xmlns:p="http://primefaces.org/ui"
   xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
   template="/WEB-INF/templates/default.xhtml"
   xmlns:pe="http://primefaces.org/ui/extensions">
   
   	<f:metadata>
	   	<f:viewParam name="articleId" value="#{articleHome.id}"></f:viewParam>
	   	<f:viewParam name="categoryId" value="#{categoryHome.id}"></f:viewParam>
	   	<f:event listener="#{articleHome.initConversation()}" type="preRenderView"></f:event>
	   	<f:viewParam name="moduleName" value="内容发布"></f:viewParam>
   	</f:metadata>
   
   	<ui:define name="content">
   
		<h:form id="editForm">         
	       <p:messages id="messages" closable="true">
	       		<p:autoUpdate />
	       	</p:messages>
	       <h:outputText  value="#{request.contextPath}" styleClass="contextPath" style="display:none"/>	
			<p:panel id="baseInfo" header="文章信息" style="margin-bottom:10px;">		        
		        <h:panelGrid columns="2" cellpadding="5">
		        	<p:outputLabel for="category" value="所属栏目"></p:outputLabel>
					<p:selectOneMenu
						id="category"
						value="#{categoryHome.instance}"
						required="true" 
					>
						<f:selectItem itemLabel="请选择" itemValue="#{null}"/>
						<f:selectItems
							value="#{categoryList.resultList}"
							var="_category"
							itemLabel="#{_category.name}"
							itemValue="#{_category}"
						></f:selectItems>
						<f:converter converterId="entityConverter"></f:converter>
					</p:selectOneMenu>
					
					<p:outputLabel for="title" value="标题" />				
					<p:inputText id="title" 
							  value="#{articleHome.instance.title}"
						   required="true"
						 styleClass="input-large" />
						   
					<p:outputLabel for="color" value="标题颜色" />				
					<p:selectOneMenu id="color" readOnly="true"
								  value="#{articleHome.instance.color}">
						<f:selectItem itemLabel="请选择" itemValue="#{null}"/>
						<f:selectItem itemLabel="红色" itemValue="red"/>
						<f:selectItem itemLabel="绿色" itemValue="green"/>
						<f:selectItem itemLabel="蓝色" itemValue="blue"/>
						<f:selectItem itemLabel="黄色" itemValue="yellow"/>
						<f:selectItem itemLabel="橘色" itemValue="orange"/>
					</p:selectOneMenu>
					
				<ui:remove>
					<p:outputPanel>
						<p:outputLabel for="image" value="文章图片" />
					</p:outputPanel>
					<p:fileUpload id="image"
								  mode="advanced"
								  skinSimple="true"
								  fileLimit="1"
								  fileLimitMessage="只能上传一个附件"
								  allowTypes="/(\.|\/)(jpe?g|png|bmp)$/"
								  sizeLimit="#{1024 * 1024 * 3}"
								  uploadLabel="上传"
								  cancelLabel="取消"
								  update="@form:image"
								  fileUploadListener="#{articleHome.uploadImage}"></p:fileUpload>
				</ui:remove>
					
					<p:outputLabel for="keywords" value="关键字" />				
					<p:inputText id="keywords" 
							  value="#{articleHome.instance.keywords}" />
					
					<p:outputLabel for="description" value="描述" />
					<p:inputTextarea id="description" value="#{articleHome.instance.description}" />
					
					<p:outputLabel for="weight" value="权重" />				
					<p:inputMask id="weight"  maxlength="3" value="#{articleHome.instance.weight}" >
							<p:keyFilter regEx="/[\d\-]/" />
					</p:inputMask>
					
					<p:outputLabel for="weightDate" value="权重日期" />		
					<p:calendar  id="weightDate"  value="#{articleHome.instance.weightDate}" 
						    pattern="yyyy-MM-dd"
						     locale="zh_CN"
					inputStyleClass="input-middle"
							 showOn="button"
					  readonlyInput="true" />
								
					<p:outputLabel for="link" value="外部链接" />				
					<p:inputText   id="link" 
								value="#{articleHome.instance.link}" >
					</p:inputText>
				</h:panelGrid>
			</p:panel>
			
			<p:panel id="secondInfo" header="文章附表" style="margin-bottom:10px;">		        
		        <h:panelGrid columns="2" cellpadding="5">
					
					<p:outputLabel for="peContent" value="内容" />
					<pe:ckEditor id="peContent" 
							  value="#{articleHome.instance.articleData.content}"
							  width="100%"
							 height="400"
					   customConfig="#{request.contextPath}/resources/js/ckeditor.js">
					</pe:ckEditor>

					<p:outputLabel for="copyfrom" value="来源" />				
					<p:inputText   	id="copyfrom" 
								 value="#{articleHome.instance.articleData.copyfrom}" />

					<p:outputLabel for="attachments" value="附件" />
					<p:outputPanel id="attachments" >
						<p:fileUpload
								
								label="选择"
								mode="advanced"
								required="true"
								multiple="true"
								skinSimple="true"
								sizeLimit="#{1024 * 1024 * 3}"
								uploadLabel="上传"
								cancelLabel="取消"
								update="editForm:uploadedAttachments"
								fileUploadListener="#{articleHome.uploadAttachments}"
						/>
						<p:panel id="uploadedAttachments">
							<ul>
								<p:repeat var="_attachment"
								value="#{articleHome.instance.attachment}">
									<li style="line-height:40px;">
										<h:outputText value="#{_attachment.filename}" />
										<p:commandButton style="margin-left:10px;" value="下载" ajax="false"  icon="ui-icon-arrowthick-1-s">
									        <p:fileDownload value="#{fileDownloadView.download(_attachment)}" />
									    </p:commandButton>
									    <p:commandButton style="margin-left:10px;" value="删除" update="editForm:uploadedAttachments" actionListener="#{articleHome.removeAttachment(_attachment)}" >
									    </p:commandButton>
									    
									</li>
								</p:repeat>
							</ul>
						</p:panel>
						
					</p:outputPanel>				
					
						
				</h:panelGrid>
			</p:panel>
			
			
			<p:commandButton action="#{articleHome.saveAndFlush()}" value="保存" ajax="false" />	
			<p:commandButton action="#{articleHome.delete()}" value="删除">
				<p:confirm header="请确认" message="您确认删除记录吗?" icon="ui-icon-alert" />
			</p:commandButton>
			<p:commandButton action="#{articleHome.audit()}" value="审核" ajax="false" rendered="#{articleHome.managed &amp;&amp; articleHome.instance.stat == '0'}"/>				
			<p:commandButton action="#{articleHome.cancel()}" value="取消" immediate="true"></p:commandButton>
			<p:confirmDialog id="confirmDialog" global="true" showEffect="fade" hideEffect="explode" widgetVar="confirmDialog">
			    <p:commandButton value="确认" styleClass="ui-confirmdialog-yes"></p:commandButton>
			    <p:commandButton value="取消" immediate="true" styleClass="ui-confirmdialog-no" />
			</p:confirmDialog>
		</h:form>
		
		
	
   	</ui:define>
</ui:composition>
